import requests

param = input('请输入搜索关键字：')
url = f'https://www.sogou.com/web?query={param}'
# 目标设置了反扒机制：User—Agent校验
# 需要模拟浏览器客户端
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 SLBrowser/9.0.6.5061 SLBChan/10 SLBVPV/64-bit'
}
response = requests.get(url, headers = headers)
# response.encoding = 'utf-8'

with open('sogou.html', 'w', encoding = 'utf-8') as file:
    file.write(response.text)